<template>
  <div>
    <el-container>
      <el-header>
        <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
          <el-menu-item>
            <router-link to="/index">商品管理</router-link>
          </el-menu-item>
          <el-menu-item>
            <router-link to="/users">用户管理</router-link>
          </el-menu-item>
          <el-menu-item>
            <router-link to="/shop">结算中心</router-link>
          </el-menu-item>
          <el-menu-item>
            <router-link to="/transaction">订单管理</router-link>
          </el-menu-item>
        </el-menu>
      </el-header>

      <el-main>
        <router-view/>
      </el-main>

    </el-container>
    <!--  选择购买商品-->
    <el-table :height="400"
              :data="tableData.filter(data => !search || data.g_name.toLowerCase().includes(search.toLowerCase()))"
              max-height="500"
              style="width: 100%">
      <el-table-column
        label="商品名称"
        width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.g_name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="购买数量"
        width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.count }}</span>
        </template>
      </el-table-column>
      <!--      prop 绑定一列中要展示的值,这个值是后台传来json数据的值-->
      <el-table-column label="总金额" prop="totalPrice">
      </el-table-column>
      <!--    <el-table-column label="商品数量" prop="g_count"></el-table-column>-->
      <!--    <el-table-column label="商品生产日期" prop="g_prodate"></el-table-column>-->
      <!--    <el-table-column label="商品过期日期" prop="g_expdate"></el-table-column>-->
      <el-table-column label="商品ID" prop="g_id"></el-table-column>
      <el-table-column label="商品单价" prop="g_price"></el-table-column>
      <el-table-column label="" align="right">
        <!--        放入搜索框-->
        <template slot="header" slot-scope="scope">
          <el-input
            v-model="search"
            size="mini"
            placeholder="请输入商品名称关键字搜索"/>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
export default {
  name: 'Transaction',
  data () {
    return {
      tableData: [],
      search: ''
    }
  },
  methods: {
    findAll () {
      this.axios.get('http://localhost:8989/transaction/findAll').then(res => {
        console.log(res)
        this.tableData = res.data
      })
    }
  },
  created () {
    this.findAll()
  }
}
</script>

<style scoped>

</style>
